/**
* @desc Allows you to perform an action every X amount of seconds.  Part of the Codereck Javascript Suite.
*
* @copyright Ryan Zec 2007-2009, All Right Reserved
*
* @license BSD (see LICENSE file included, the generic templete can be found at http://www.opensource.org/licenses/bsd-license.php)
*/
(function($)
{
	//create the codereck scope
	$.cr = $.cr || {};

	//function to create new instance of a codereck beat
	$.create_beat = function(name, delay, beat_function)
	{
	    var options = {};
		options.name = name;
	    options.delay = delay
		var beat_instance = new $.cr.beat(options, beat_function);
		$('body').data(name, beat_instance);
	}

	//function to delete an instance of the codereck beat
	$.delete_beat = function(name)
	{
		$('body').data(name).clear();
		$('body').removeData(name);
	}

	//codereck tab class
	$.cr.beat = function(options, beat_function)
	{
		this.beat_function = beat_function;

		this.options = $.extend(
		{
			name: null,
			delay: 1000
		},
		options);

		this.start();
	}

	$.extend($.cr.beat.prototype, $.cr.core);
	$.extend($.cr.beat.prototype,
	{
		start: function()
		{
			this.options.timeout_object = setTimeout("$('body').data('" + this.options.name + "').beat();" , this.options.delay);
		},

		clear: function()
		{
			clearTimeout(this.options.timeout_object);
		},

		beat: function()
		{
			this.options.timeout_object = setTimeout("$('body').data('" + this.options.name + "').beat();" , this.options.delay);
			this.beat_function();
		}
	});
})(jQuery);